/*!
\copyright  Copyright (c) 2019 - 2022 Qualcomm Technologies International, Ltd.\n
            All Rights Reserved.\n
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file       earbud_pmalloc_pools.c
\brief      Definition of the pmalloc pools used by the earbud application.

The pools defined here will be merged at run time with the base definitions
from OS - see 'pmalloc_config_P1.h'.
*/

#include <pmalloc.h>

_Pragma ("unitsuppress Unused")

_Pragma ("datasection apppool")

#ifdef USE_SYNERGY

#ifdef INCLUDE_LE_AUDIO_UNICAST

/* Additional the pools memory for LE Audio support:
   Additional blocks: 102
   Additional bytes:  3784
*/
#define APP_POOL_BLOCK_SIZE_4_ADDON_COUNT       20
#define APP_POOL_BLOCK_SIZE_8_ADDON_COUNT        3
#define APP_POOL_BLOCK_SIZE_12_ADDON_COUNT       7
#define APP_POOL_BLOCK_SIZE_16_ADDON_COUNT       4
#define APP_POOL_BLOCK_SIZE_20_ADDON_COUNT      19
#define APP_POOL_BLOCK_SIZE_24_ADDON_COUNT       4
#define APP_POOL_BLOCK_SIZE_28_ADDON_COUNT      12
#define APP_POOL_BLOCK_SIZE_32_ADDON_COUNT       0
#define APP_POOL_BLOCK_SIZE_36_ADDON_COUNT       1
#define APP_POOL_BLOCK_SIZE_44_ADDON_COUNT       2
#define APP_POOL_BLOCK_SIZE_56_ADDON_COUNT       3
#define APP_POOL_BLOCK_SIZE_64_ADDON_COUNT       4
#define APP_POOL_BLOCK_SIZE_80_ADDON_COUNT      16
#define APP_POOL_BLOCK_SIZE_100_ADDON_COUNT      2
#define APP_POOL_BLOCK_SIZE_128_ADDON_COUNT      3
#define APP_POOL_BLOCK_SIZE_160_ADDON_COUNT      2
#define APP_POOL_BLOCK_SIZE_180_ADDON_COUNT      0
#define APP_POOL_BLOCK_SIZE_220_ADDON_COUNT      0
#define APP_POOL_BLOCK_SIZE_512_ADDON_COUNT      0
#define APP_POOL_BLOCK_SIZE_692_ADDON_COUNT      0
#define APP_POOL_BLOCK_SIZE_1400_ADDON_COUNT     0

#else /* INCLUDE_LE_AUDIO_UNICAST */

#define APP_POOL_BLOCK_SIZE_4_ADDON_COUNT        0
#define APP_POOL_BLOCK_SIZE_8_ADDON_COUNT        0
#define APP_POOL_BLOCK_SIZE_12_ADDON_COUNT       0
#define APP_POOL_BLOCK_SIZE_16_ADDON_COUNT       0
#define APP_POOL_BLOCK_SIZE_20_ADDON_COUNT       0
#define APP_POOL_BLOCK_SIZE_24_ADDON_COUNT       0
#define APP_POOL_BLOCK_SIZE_28_ADDON_COUNT       0
#define APP_POOL_BLOCK_SIZE_32_ADDON_COUNT       0
#define APP_POOL_BLOCK_SIZE_36_ADDON_COUNT       0
#define APP_POOL_BLOCK_SIZE_44_ADDON_COUNT       0
#define APP_POOL_BLOCK_SIZE_56_ADDON_COUNT       0
#define APP_POOL_BLOCK_SIZE_64_ADDON_COUNT       0
#define APP_POOL_BLOCK_SIZE_80_ADDON_COUNT       0
#define APP_POOL_BLOCK_SIZE_100_ADDON_COUNT      0
#define APP_POOL_BLOCK_SIZE_128_ADDON_COUNT      0
#define APP_POOL_BLOCK_SIZE_160_ADDON_COUNT      0
#define APP_POOL_BLOCK_SIZE_180_ADDON_COUNT      0
#define APP_POOL_BLOCK_SIZE_220_ADDON_COUNT      0
#define APP_POOL_BLOCK_SIZE_512_ADDON_COUNT      0
#define APP_POOL_BLOCK_SIZE_692_ADDON_COUNT      0
#define APP_POOL_BLOCK_SIZE_1400_ADDON_COUNT     0

#ifdef INCLUDE_AUDIOREACH
#define APP_POOL_BLOCK_SIZE_5000_ADDON_COUNT     0
#define APP_POOL_BLOCK_SIZE_10000_ADDON_COUNT     0
#endif

#endif /* INCLUDE_LE_AUDIO_UNICAST */

/* Additional pools required when TDL is extended to 12 devices */
#define APP_POOL_BLOCK_SIZE_8_EXTENDED_TDL      12
#define APP_POOL_BLOCK_SIZE_16_EXTENDED_TDL     36
#define APP_POOL_BLOCK_SIZE_20_EXTENDED_TDL     6
#define APP_POOL_BLOCK_SIZE_24_EXTENDED_TDL     6
#define APP_POOL_BLOCK_SIZE_28_EXTENDED_TDL     30
#define APP_POOL_BLOCK_SIZE_36_EXTENDED_TDL     6

#ifdef INCLUDE_ACCESSORY_TRACKING
#define APP_POOL_BLOCK_SIZE_128_ACCESSORY_TRACKING  40
#define APP_POOL_BLOCK_SIZE_1400_ACCESSORY_TRACKING 2
#else
#define APP_POOL_BLOCK_SIZE_128_ACCESSORY_TRACKING  0
#define APP_POOL_BLOCK_SIZE_1400_ACCESSORY_TRACKING 0
#endif

/* Additional pool required when Google Finder is enabled.
   Those pools are required because in some circumstances all the messages sent by the device_sync
   may be present in the message queue at the same time.
   Pool required by message queue to send any message is 28 bytes.
   Pool needed for Google Finder device property is 36 bytes..
 */
#define APP_POOL_BLOCK_SIZE_28_GOOGLE_FINDER    1
#define APP_POOL_BLOCK_SIZE_36_GOOGLE_FINDER    1

#define APP_POOL_BLOCK_SIZE_4_BASE_COUNT        15
#define APP_POOL_BLOCK_SIZE_8_BASE_COUNT        25 + APP_POOL_BLOCK_SIZE_8_EXTENDED_TDL
#define APP_POOL_BLOCK_SIZE_12_BASE_COUNT       32
#define APP_POOL_BLOCK_SIZE_16_BASE_COUNT       58 + APP_POOL_BLOCK_SIZE_16_EXTENDED_TDL
#define APP_POOL_BLOCK_SIZE_20_BASE_COUNT       42 + APP_POOL_BLOCK_SIZE_20_EXTENDED_TDL
#define APP_POOL_BLOCK_SIZE_24_BASE_COUNT       20 + APP_POOL_BLOCK_SIZE_24_EXTENDED_TDL
#define APP_POOL_BLOCK_SIZE_28_BASE_COUNT       79 + APP_POOL_BLOCK_SIZE_28_EXTENDED_TDL + APP_POOL_BLOCK_SIZE_28_GOOGLE_FINDER
#define APP_POOL_BLOCK_SIZE_32_BASE_COUNT       21
#define APP_POOL_BLOCK_SIZE_36_BASE_COUNT       19 + APP_POOL_BLOCK_SIZE_36_EXTENDED_TDL + APP_POOL_BLOCK_SIZE_36_GOOGLE_FINDER
#define APP_POOL_BLOCK_SIZE_44_BASE_COUNT       24
#define APP_POOL_BLOCK_SIZE_56_BASE_COUNT       14
#define APP_POOL_BLOCK_SIZE_64_BASE_COUNT       10
#define APP_POOL_BLOCK_SIZE_80_BASE_COUNT       16
#define APP_POOL_BLOCK_SIZE_100_BASE_COUNT       0
/* One of 128 bytes blocks is added for DeviceDbSerialiser_MakeBackup() */
#define APP_POOL_BLOCK_SIZE_128_BASE_COUNT      19 + APP_POOL_BLOCK_SIZE_128_ACCESSORY_TRACKING
#define APP_POOL_BLOCK_SIZE_160_BASE_COUNT       8
#define APP_POOL_BLOCK_SIZE_180_BASE_COUNT       2
#define APP_POOL_BLOCK_SIZE_220_BASE_COUNT       2
/* One of this blocks has been added for AMA hairpin functionality. */
#define APP_POOL_BLOCK_SIZE_512_BASE_COUNT       8
#define APP_POOL_BLOCK_SIZE_692_BASE_COUNT       2
#ifdef INCLUDE_AUDIOREACH
#define APP_POOL_BLOCK_SIZE_5000_BASE_COUNT      3
#define APP_POOL_BLOCK_SIZE_10000_BASE_COUNT      2
#endif
#define APP_POOL_BLOCK_SIZE_1400_BASE_COUNT      0 + APP_POOL_BLOCK_SIZE_1400_ACCESSORY_TRACKING

#define APP_POOL_BLOCK_ENTRY(size) \
    {size, APP_POOL_BLOCK_SIZE_##size##_BASE_COUNT + APP_POOL_BLOCK_SIZE_##size##_ADDON_COUNT}


static const pmalloc_pool_config app_pools[] =
{
    APP_POOL_BLOCK_ENTRY(4),
    APP_POOL_BLOCK_ENTRY(8),
    APP_POOL_BLOCK_ENTRY(12),
    APP_POOL_BLOCK_ENTRY(16),
    APP_POOL_BLOCK_ENTRY(20),
    APP_POOL_BLOCK_ENTRY(24),
    APP_POOL_BLOCK_ENTRY(28),
    APP_POOL_BLOCK_ENTRY(32),
    APP_POOL_BLOCK_ENTRY(36),
    APP_POOL_BLOCK_ENTRY(44),
    APP_POOL_BLOCK_ENTRY(56),
    APP_POOL_BLOCK_ENTRY(64),
    APP_POOL_BLOCK_ENTRY(80),
#ifdef INCLUDE_LE_AUDIO_UNICAST
    APP_POOL_BLOCK_ENTRY(100),
#endif
    APP_POOL_BLOCK_ENTRY(128),
    APP_POOL_BLOCK_ENTRY(160),
    APP_POOL_BLOCK_ENTRY(180),
    APP_POOL_BLOCK_ENTRY(220),
    APP_POOL_BLOCK_ENTRY(512),
    APP_POOL_BLOCK_ENTRY(692),
#ifdef INCLUDE_ACCESSORY_TRACKING
    APP_POOL_BLOCK_ENTRY(1400),
#endif
#ifdef INCLUDE_AUDIOREACH
    APP_POOL_BLOCK_ENTRY(5000),
    APP_POOL_BLOCK_ENTRY(10000)
#endif
};

#else /* USE_SYNERGY */

static const pmalloc_pool_config app_pools[] =
{
    {   4, 15 },
    {   8, 25 },
    {  12, 32 },
    {  16, 13 },
    {  20, 31 },
    {  24, 20 },
    {  28, 55 },
    {  32, 21 },
    {  36, 19 },
    {  40, 10 },
    {  56,  9 },
    {  64,  7 },
    {  80,  9 },
    { 124, 15 }, /* One of this blocks is added for DeviceDbSerialiser_MakeBackup() */
    { 160,  8 },
    { 180,  2 },
    { 220,  2 },
    { 288,  1 }, /* for theGatt = gattState */
    { 512,  2 }, /* One of this blocks has been added for AMA hairpin functionality. */
    { 692,  2 },

#ifdef INCLUDE_AUDIOREACH
    { 1300, 3 }
#endif
};

#endif /* USE_SYNERGY */

